package com.ider.launcherpackage.common;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;

import com.ider.launcherpackage.launcher.PackageHolder;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;


public class ApplicationUtil {
    /**
     * com.softwinner.dragonbox
     com.android.camera2
     */
    private final static String APP_VTVPLAY_HIDE="vn.vtvplay.ottbox.app";
    public static List<PackageHolder> queryApplication(Context context,boolean vtvIsHide) {
        List<PackageHolder> enties = new ArrayList<>();

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        PackageManager packageManager = context.getPackageManager();
        List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0);

        if (vtvIsHide){
            for (ResolveInfo resolveInfo : resolveInfos) {
                String packageName = resolveInfo.activityInfo.applicationInfo.packageName;
                if (!packageName.equals("com.ider.launcherpackage")
                        &&!packageName.equals(APP_VTVPLAY_HIDE)
                        &&!packageName.equals("com.android.camera2")) {

                    enties.add(new PackageHolder(packageName, null));
                }
            }
        }else {
            for (ResolveInfo resolveInfo : resolveInfos) {
                String packageName = resolveInfo.activityInfo.applicationInfo.packageName;
                if (!packageName.equals("com.ider.launcherpackage")
                        &&!packageName.equals("com.android.camera2")) {

                    enties.add(new PackageHolder(packageName, null));
                }
            }
        }
        HashSet h = new HashSet(enties);//删除重复元素
        enties.clear();
        enties.addAll(h);
        return enties;
    }



}
